From 685f2b4ee783d2e710d8ece66db5b28a7e274351 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 11 Jul 2014 09:08:51 -0700 Subject: [PATCH] Add some simple tests for cross compilation --- tests/support/mod.rs | 5 ++ tests/test_cargo_cross_compile.rs | 78 +++++++++++++++++++++++++++++++ tests/tests.rs | 1 + 3 files changed, 84 insertions(+) create mode 100644 tests/test_cargo_cross_compile.rs diff --git a/tests/support/mod.rs b/tests/support/mod.rs index 90a3542ff..fd99e08d8 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -101,6 +101,11 @@ impl ProjectBuilder { self.build_dir().join(format!("{}{}", b, os::consts::EXE_SUFFIX)) } + pub fn target_bin(&self, target: &str, b: &str) -> Path { + self.build_dir().join(target).join(format!("{}{}", b, + os::consts::EXE_SUFFIX)) + } + pub fn build_dir(&self) -> Path { self.root.join("target") } diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs new file mode 100644 index 000000000..4bc4ddc60 --- /dev/null +++ b/tests/test_cargo_cross_compile.rs @@ -0,0 +1,78 @@ +// Currently the only cross compilers available via nightlies are on linux/osx, +// so we can only run these tests on those platforms +#![cfg(target_os = "linux")] +#![cfg(target_os = "macos")] + +use std::os; + +use support::{project, execs, basic_bin_manifest}; +use hamcrest::{assert_that, existing_file}; +use cargo::util::process; + +fn setup() { +} + +fn alternate() -> &'static str { + match os::consts::SYSNAME { + "linux" => "i686-unknown-linux-gnu", + "darwin" => "i686-apple-darwin", + _ => unreachable!(), + } +} + +test!(simple_cross { + let p = project("foo") + .file("Cargo.toml", basic_bin_manifest("foo").as_slice()) + .file("src/foo.rs", r#" + use std::os; + fn main() { + assert_eq!(os::consts::ARCH, "x86"); + } + "#); + + let target = alternate(); + assert_that(p.cargo_process("cargo-build").arg("--target").arg(target), + execs().with_status(0)); + assert_that(&p.target_bin(target, "foo"), existing_file()); + + assert_that( + process(p.target_bin(target, "foo")), + execs().with_status(0)); +}) + +test!(simple_deps { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies.bar] + path = "../bar" + "#) + .file("src/main.rs", r#" + extern crate bar; + fn main() { bar::bar(); } + "#); + let p2 = project("bar") + .file("Cargo.toml", r#" + [package] + name = "bar" + version = "0.0.1" + authors = [] + "#) + .file("src/lib.rs", "pub fn bar() {}"); + p2.build(); + + let target = alternate(); + assert_that(p.cargo_process("cargo-build").arg("--target").arg(target), + execs().with_status(0)); + assert_that(&p.target_bin(target, "main"), existing_file()); + + assert_that( + process(p.target_bin(target, "main")), + execs().with_status(0)); +}) + + diff --git a/tests/tests.rs b/tests/tests.rs index bb5bf9739..595287a18 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -26,3 +26,4 @@ mod test_cargo_compile_git_deps; mod test_cargo_compile_path_deps; mod test_cargo_test; mod test_shell; +mod test_cargo_cross_compile; -- 2.30.2